<template>
  <component :is="ele" v-model="v" v-bind="propv">    
  </component>
  <el-button @click="this.showDialog=true">编辑样式</el-button>
  <el-dialog
    v-model="showDialog"
    title="Tips"
    width="30%"    
  >
    <el-form v-model="propv">
      <el-form-item v-for="item in pp" :label="item.id" :key="item.id">    
        <el-select v-model="propv[item.id]" v-if="item.options">
          <el-option v-for="o in item.options" :key="o" :label="o" :value="o"></el-option>
        </el-select>
        <el-switch v-model="propv[item.id]" v-else-if="item.type===Boolean"></el-switch>
        <el-input-number v-model="propv[item.id]" v-else-if="item.type===Number"></el-input-number>
        <el-input v-model="propv[item.id]" v-else></el-input>    
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
import cfg from '../config/componentsProps'
export default {
  created(){
    console.log('created');
    this.changedEle();
  },
  props:{
    ele:String
  },
  watch:{
    ele(n,o){
      if(n!==o){
        this.changedEle()
      }
    }
  },
  methods:{
    changedEle(){
      if(this.ele!==undefined){
      this.pp=cfg[this.ele]
      this.v=""
      this.pp.forEach(element => {      
        let v=element.default
        if(v===undefined){
          v=""
        }
        if(element.type===String){        
          this.propv[element.id]=v
        }
        else if(element.type===String|Number){
          this.propv[element.id]=v
        }
        else if (element.type===Boolean){
          this.propv[element.id]=false
        }
        else if (element.type===Number){
          this.propv[element.id]=0
        }
      });
      console.log(this.propv);
    }    
    }
  },
  data(){
    return {
      showDialog:false,
      v:"",      
      propv:{        
      },
      // ele:"ElButton", //ElSwitch ElButtonn ElInput
      pp:[]
    }
  }
}
</script>

<style>

</style>